package onest.springboot.mybatis.demo.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInterceptor;
import onest.springboot.mybatis.demo.dao.UserMapper;
import onest.springboot.mybatis.demo.entity.User;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import javax.annotation.Resource;

@Service
public class UserService {
	@Resource
	UserMapper userMapper;

	public Page<User> getAll(){
		PageHelper.startPage(1,2);

		return (Page<User>)userMapper.findAll();
	}
	public void saveUser(User user) {
		userMapper.insertUser(user);
	}
	@Async
	public void task() {
		for(int i=0;i<30;i++){
			System.out.println(Thread.currentThread().getName());
			try {
				Thread.sleep(2000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}

		}

	}
}
